package com.blacktea.behavioralpatterns.observerpattern.event;

import com.blacktea.behavioralpatterns.observerpattern.Order;
import com.blacktea.behavioralpatterns.observerpattern.OrderStatus;
import com.blacktea.behavioralpatterns.observerpattern.OrderStatusChangeEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @description: 库存系统
 * @author: black tea
 * @date: 2023/3/25 22:53
 */
@Component
@Slf4j
public class InventorySystem implements ApplicationListener<OrderStatusChangeEvent> {

    @Override
    public void onApplicationEvent(OrderStatusChangeEvent event) {
        Order order = event.getOrder();
        if (order.getStatus() == OrderStatus.PAID) {
            // 扣减库存
            log.info("扣减库存操作");
        }
    }
}
